package com.sxbbc.seller.controller;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sxbbc.common.basics.utils.date.DateUtil;
import com.sxbbc.common.basics.utils.export.ExportUtil;
import com.sxbbc.common.basics.utils.statics.StaticUtils;
import com.sxbbc.common.core.entity.jz.OrderMain;
import com.sxbbc.common.core.service.IOrderMainService;
import com.sxbbc.common.core.utils.BasePage;
import com.sxbbc.seller.common.ExportMapping;
import com.sxbbc.seller.service.ExportService;
import com.sxbbc.seller.util.BusinessSession;

/**
 * 数据导出controller
 * @author xiaoky
 * @date 2019-07-07
 */
@Controller
public class ExportController {
	@Autowired
	private HttpServletRequest request;
	@Autowired
	private HttpServletResponse response;
	@Autowired
	private IOrderMainService orderMainService;
	@Autowired
	private ExportService exportService;
	
	/**
	 * 导出会员订单数据
	 * @param page 分页
	 * @param orderMain 订单查询条件
	 * @author xiaoky
	 */
	@RequestMapping(value = ExportMapping.HANDLE_EXPORT_ORDER)
	@ResponseBody
	public void exportOrder (BasePage<OrderMain> page, OrderMain orderMain) {
		page.setSize(StaticUtils.EXCEL_MAX_LINE);
		Integer bid = BusinessSession.getBid(request);
		orderMain.setBid(bid);
		// 查询未删除的订单
		orderMain.setDel(StaticUtils.STATUS_NO);
		// 订单列表
		orderMainService.queryOrder(page, orderMain);
		// 查询未删除的订单
		HSSFWorkbook wb = exportService.exportOrder(page.getRecords());
		ExportUtil export = ExportUtil.getInstance();
		String fileName = "会员订单列表_" + DateUtil.getInstance().toDateString(new Date()) + ".xls";
		export.exportFiles(response,fileName,wb);
	}
}
